<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .a {
        color: red;
      }
      .b {
        font-size: 4rem;
      }

      .c {
        border: solid;
      }
    </style>
  </head>
  <body>
    <div id="box" class="a">hello div</div>
    <script>
      const box = document.getElementById("box");

      setTimeout(() => {
        console.log(box.classList.contains("a")); //true
        console.log(box.classList.contains("c")); //false

        // 如果 b 存在则删除b，如果b不存在则添加b
        box.classList.toggle("b");
        box.classList.toggle("a");
      }, 3000);

      setInterval(() => {
        // 如果 b 存在则删除b，如果b不存在则添加b
        // box.classList.toggle("b");
        // box.classList.toggle("a");
      }, 2000);
    </script>
  </body>
</html>
